﻿using System;
using System.Linq.Expressions;
using WindowsPhoneMvp.Navigation;
using System.ComponentModel;
using WindowsPhoneMvp.Util;
using System.Runtime.CompilerServices;

namespace WindowsPhoneMvp
{
    [BindAsViewModel]
    public class PresentingViewModel : Presenter<IView>, INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged = delegate { };

        public PresentingViewModel(IView view) : base(view)
        {
            view.Load += (sender, args) => Loaded();
        }

        protected virtual void Loaded()
        {
            
        }

        public PresentingViewModel(IView view, INavigationService navigationService) : base(view, navigationService)
        {
        }

        protected void RaisePropertyChanged([CallerMemberName] string propertyName = null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }

        protected void RaisePropertyChanged(Expression<Func<object>> property)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(Property.GetFor(property)));
        }
    }
}